<template>
  <div class="app-container">
    <el-row type="flex">
      <!-- 工单统计 -->
      <el-col :span="18">
        <el-row type="flex" class="el-rowBox">
          <el-col :span="13">
            <div class="box1 user-task-stats-chart bgc1">
              <el-row>
                <div class="title">
                  <h3>工单统计 <span class="spanSize">{{ startMonth|formatDate }} - {{ startDate |formatDate }}</span></h3>
                </div>
              </el-row>
              <el-row type="flex" justify="center">
                <el-col>
                  <div class="num color1 text-shadow1">{{ workerData.total }}</div>
                  <div class="text color2">工单总数（个）</div>
                </el-col>
                <el-col>
                  <div class="num color1 text-shadow1">{{ workerData.completedTotal }}</div>
                  <div class="text color2">完成工单（个）</div>
                </el-col>
                <el-col>
                  <div class="num color1 text-shadow1">{{ workerData.progressTotal }}</div>
                  <div class="text color2">进行工单（个）</div>
                </el-col>
                <el-col>
                  <div class="num color1 text-shadow1">{{ workerData.cancelTotal }}</div>
                  <div class="text color2">取消工单（个）</div>
                </el-col>

              </el-row>
            </div>
          </el-col>
          <el-col :span="11">
            <div class="box2 user-task-stats-chart bgc2">
              <el-row>
                <div class="title">
                  <h3>销售统计 <span class="spanSize">{{ startMonth|formatDate }} - {{ startDate |formatDate }}</span></h3>
                </div>
              </el-row>
              <el-row type="flex" justify="center">
                <el-col>
                  <div class="num color3 text-shadow2">{{ orderNum }}</div>
                  <div class="text color4">订单量（个）</div>
                </el-col>
                <el-col>
                  <div class="num color3 text-shadow2">{{ (saleValue/1000000).toFixed(2) }}</div>
                  <div class="text color4">销售额（万元）</div>
                </el-col>
              </el-row>
            </div>
          </el-col>
        </el-row>
        <div class="box sku-sale-collect">
          <!-- 折线图柱形图组件 -->
          <SalesData />
        </div>
      </el-col>
      <!-- 商品热榜 -->
      <el-col :span="6">
        <div class="box3 user-task-stats-chart bgc3">
          <el-row>
            <div class="title">
              <h3>商品热榜 <span class="spanSize">{{ startMonth|formatDate }} - {{ startDate |formatDate }}</span></h3>
            </div>
          </el-row>
          <div class="body">
            <!-- 排行榜 -->
            <el-row v-for="(item,index) in SkuTopData" :key="item.skuName" type="flex" justify="center" class="left-row">
              <el-col :span="5" class="top top1" :class="{top2:index===1,top3:index===2,top4:index!==0&&index!==1&&index!==2}">
                {{ index+1 }}
              </el-col>
              <el-col :span="13" class="centerWord">
                {{ item.skuName }}
              </el-col>
              <el-col :span="6">
                {{ item.count }}单
              </el-col>
            </el-row>
          </div>
        </div>
      </el-col>
    </el-row>
    <el-row type="flex">
      <el-col :span="14">
        <div class="box partner-node-collect">
          <el-row type="flex">
            <el-col :span="20">
              <div class="title">
                <h3>合作商点位数Top5 </h3>
              </div>
            </el-col>
            <el-col :span="4">
              <div class="iconBox">
                <i class="el-icon-chat-dot-round" @click="$router.push('/node/partner')" />
              </div>
            </el-col>
          </el-row>
          <el-row type="flex">
            <!-- 放置饼图 -->
            <el-col :span="17">
              <PieChart />
            </el-col>
            <el-col :span="7">
              <div class="collect">
                <div class="count">{{ totalCount }}</div>
                <div class="name">点位数</div>
                <div class="count count2">{{ partnerNum }}</div>
                <div class="name">合作商数</div>
              </div>
            </el-col>
          </el-row>
        </div>
      </el-col>
      <el-col :span="10">
        <div class="box abnormal-equipment left-shifting">
          <el-row type="flex">
            <el-col :span="20">
              <div class="title">
                <h3>异常设备监控</h3>
              </div>
            </el-col>
            <el-col :span="4">
              <div class="iconBox">
                <i class="el-icon-chat-dot-round" @click="$router.push('/vm/status')" />
              </div>
            </el-col>
          </el-row>
          <el-row>
            <div v-if="deviceNum.length>0" class="empty">
              <el-row v-for="item in deviceNum" :key="item" type="flex">
                <el-col>
                  编号:{{ item.innerCode }}
                </el-col>
                <el-col>
                  地址:{{ item.address }}
                </el-col>
                <el-col>
                  故障时间:{{ item.time }}
                </el-col>
              </el-row>
            </div>
            <div v-else class="tips">
              <img src="@/assets/common/noshuju.png" alt="">
              <div>暂无数据</div>
            </div>
          </el-row>
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script>

import PieChart from './components/pie-chart.vue'
import SalesData from './components/sales-data.vue'
import { workOrderListAPI,
  TotalNumberAPI,
  TotalMoneyAPI,
  skuTopAPI,
  TotalCountAPI,
  PartnerNumberAPI,
  FaultyEquipmentAPI
} from '@/api/SummaryInformation'
import moment from 'moment'
export default {
  components: {
    PieChart,
    SalesData
  },
  data() {
    return {
      startDate: '',
      startMonth: '',
      // 工单统计数据
      workerData: {},
      // 订单量
      orderNum: 0,
      // 销售额
      saleValue: 0,
      // 销售前几的数据
      SkuTopData: [],
      // 点位数
      totalCount: 0,
      // 合作商数
      partnerNum: 0,
      deviceNum: 0

    }
  },
  created() {
    this.getUserWorkTime()
    this.getWorkOderInfo()
    this.getSalesStatistics()
    this.getSkuTop()
    this.getTotalCount()
  },
  methods: {
    // 获取用户工作时间
    getUserWorkTime() {
      // 现在时间
      this.startDate = moment().format('YYYY-MM-DD HH:mm:ss')
      // console.log(this.startDate)
      // 本月4.1
      this.startMonth = moment().month(moment().month()).startOf('month').format('YYYY-MM-DD 00:00:00')
      // console.log(this.startMonth)
    },
    // 获取工单统计数量
    async   getWorkOderInfo() {
      const res = await workOrderListAPI(this.startMonth, this.startDate)
      // 取消订单
      const result1 = res.data.reduce((sum, item) => {
        return { cancelTotal: sum.cancelTotal + item.cancelTotal }
      })
      // 完成工单
      const result2 = res.data.reduce((sum, item) => {
        return { completedTotal: sum.completedTotal + item.completedTotal }
      })
      // 工单总数
      const result3 = res.data.reduce((sum, item) => {
        return { total: sum.total + item.total }
      })
      // 进行工单
      const result4 = res.data.reduce((sum, item) => {
        return { progressTotal: sum.progressTotal + item.progressTotal }
      })
      this.workerData = { ...result1, ...result2, ...result3, ...result4 }
    },
    // 获取销售统计
    async  getSalesStatistics() {
      const res = await TotalNumberAPI({
        start: this.startMonth,
        end: this.startDate
      })
      this.orderNum = res.data
      const res2 = await TotalMoneyAPI({
        start: this.startMonth,
        end: this.startDate
      })
      this.saleValue = res2.data
    },
    // 获取销售前几的数据
    async   getSkuTop() {
      // 现在时间
      const startDate = moment().format('YYYY-MM-DD')
      // 本月4.1
      const startMonth = moment().month(moment().month()).startOf('month').format('YYYY-MM-DD')
      const res = await skuTopAPI(startMonth, startDate)
      this.SkuTopData = res.data
    },
    // 获取点位总数和合作商数和故障设备
    async  getTotalCount() {
      // 点位数
      const res = await TotalCountAPI()
      this.totalCount = res.data
      // 合作商数
      const res2 = await PartnerNumberAPI()
      this.partnerNum = res2.data
      // 故障设备数
      const res3 = await FaultyEquipmentAPI()
      this.deviceNum = res3.data
    }
  }
}
</script>

<style lang="scss" scoped>
.el-rowBox {

.bgc1 {
  background-color: #e9f3ff;
  background-repeat: no-repeat,no-repeat;
  background-image: url('~@/assets/common/leftbeijing.png'),url('~@/assets/common/yunybeijing.png');
  background-position: 0 0,calc(100% - 12px) 100%;
  .title h3 {
    margin: 0;
    padding: 0;
    .spanSize {
      font-weight: normal;
      color: #666;
      font-size: 12px;
    }
  }
  .el-col-12first{
    padding-left: 10px;
    padding-right: 10px;
  }
  .text-shadow1 {
    text-shadow: 2px 4px 7px rgba(85,132,255,.5);
  }
  .color1 {
    color: #072074;
  }
  .num {
    height: 50px;
  font-size: 36px;
  font-family: PingFangSC-Semibold,PingFang SC;
  font-weight: 600;
  line-height: 50px;
  text-align: center;
  margin-top: 15px;
  }
  .text {
    height: 17px;
  margin-top: 13px;

  font-size: 12px;
  font-family: PingFangSC-Regular,PingFang SC;
  font-weight: 400;
  line-height: 17px;
  text-align: center;
  }
  .color2 {
    color: #91a7dc;
  }
}
.bgc2 {
  background: #fbefe8 url('~@/assets/common/rightbeijing.png') no-repeat calc(100% - 12px) 100%;
  .title h3 {
    margin: 0;
    padding: 0;
    .spanSize {
      font-weight: normal;
      color: #666;
      font-size: 12px;
    }
  }
  .el-col-12first{
    padding-left: 10px;
    padding-right: 10px;
  }
  .text-shadow2 {
    text-shadow: 2px 4px 7px rgba(255,99,85,.5);
  }
  .color3 {
    color: #ff5757;
  }
  .num {
    height: 50px;
  font-size: 36px;
  font-family: PingFangSC-Semibold,PingFang SC;
  font-weight: 600;
  line-height: 50px;
  text-align: center;
  margin-top: 15px;
  }
  .text {
    height: 17px;
  margin-top: 13px;

  font-size: 12px;
  font-family: PingFangSC-Regular,PingFang SC;
  font-weight: 400;
  line-height: 17px;
  text-align: center;
  }
  .color4 {
    color: #de9690;
  }
}
.user-task-stats-chart {
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-orient: vertical;
  -webkit-box-direction: normal;
  -ms-flex-direction: column;
  flex-direction: column;
  height: calc(25vh - 30px);
  min-height: 166px;
}
.box1 {
  padding: 20px;
  border-radius: 20px;
  margin-right: 6px;
}
.box2 {
  padding: 20px;
  border-radius: 20px;
  margin-left: 6px;
}

}
.sku-sale-collect {

    display: flex;
    -webkit-box-orient: vertical;
    -webkit-box-direction: normal;

    flex-direction: column;
    height: calc(40vh - 68px);
    min-height: 352px;
    margin-top: 20px;
    background: #fff;
    border-radius: 20px;
    .title h3 {
    margin: 0;
    padding: 0;
    .spanSize {
      font-weight: normal;
      color: #666;
      font-size: 12px;
    }
  }
  .rightWord {
    text-align: right;
    .week-month-year {
    display: flex;
    -webkit-box-pack: center;
    justify-content: center;
    -webkit-box-align: center;
    align-items: center;
    // padding: 20px;
::v-deep .el-tabs--card>.el-tabs__header {
  border: none;
}
  ::v-deep.el-tabs--card>.el-tabs__header .el-tabs__nav {
    border: none

}
::v-deep .el-tabs--card>.el-tabs__header .el-tabs__item {
  border: none
}
.el-tabs__nav2 {
  height: 40px;
    background: rgba(233,243,255,.37);
    border-radius: 10px;
    .top {
      display: inline-block;
    margin-left: 10px;
    text-align: center;
    font-size: 12px;
    font-family: zihun143-zhengkuchaojihei,zihun143;
    font-weight: 400;

    line-height: 14px;
    }
    .top1 {
      width: 21px;
    height: 20px;
    background: url('~@/assets/common/jiangbei.png');
    color: #8e5900;
    }
    .user-name {
      height: 20px;
    font-size: 14px;
    font-family: PingFangSC-Medium,PingFang SC;
    font-weight: 500;
    color: #333;
    line-height: 20px;
    margin-left: 20px;
    }
    .work-count {
      height: 20px;
    font-size: 14px;
    font-family: PingFangSC-Regular,PingFang SC;
    font-weight: 400;
    color: #737589;
    line-height: 20px;
    text-align: right;
    }
}
::v-deep .el-tabs--card>.el-tabs__header .el-tabs__item.is-active {
  background: #e7e5e5;
    -webkit-box-shadow: 0 0 4px 0 rgba(0,0,0,.11);
    box-shadow: 0 0 4px 0 rgba(0,0,0,.11);
     border-radius: 7px;
    font-weight: 600;
    color: #333;
}

.tips {
  text-align: center;

}
    }
  }
}
.box {
  padding: 20px;
}
.bgc3 {
  background-color: #ffffff;

  .title h3 {
    margin: 0;
    padding: 0;
    .spanSize {
      font-weight: normal;
      color: #666;
      font-size: 12px;
    }
  }
  .body {
    display: flex;
    flex: 1;
    justify-content: space-between;
    flex-direction: column;
    margin-top: 20px;
    -webkit-box-orient: vertical;
    -webkit-box-direction: normal;
    .left-row {
      padding: 13px 0 13px 0 ;
      .top {
      display: inline-block;
    margin-right: 30px;
    text-align: center;
    font-size: 12px;
    font-family: zihun143-zhengkuchaojihei,zihun143;
    font-weight: 400;
    line-height: 14px;
    }
    .centerWord {
      margin-right: 40px;
    }
    .top1 {
      width: 26px;
    height: 20px;
    background: url('~@/assets/common/jiangbei.png');
    color: #8e5900;
    }
    .top2 {
      width: 26px;
    height: 20px;
    background: url('~@/assets/common/yinsejiangbei.png');
    color: #8e5900;
    }
    .top3 {
      width: 26px;
    height: 20px;
    background: url('~@/assets/common/jiangbei3.png');
    color: #8e5900;
    }
    .top4 {
      width: 26px;
    height: 20px;
    background: url('~@/assets/common/jiangbei4.png');
    color: #e9b499;
    }
    }
  }
  .el-col-12first{
    padding-left: 10px;
    padding-right: 10px;
  }
  .text-shadow1 {
    text-shadow: 2px 4px 7px rgba(85,132,255,.5);
  }
  .color1 {
    color: #072074;
  }
  .num {
    height: 50px;
  font-size: 36px;
  font-family: PingFangSC-Semibold,PingFang SC;
  font-weight: 600;
  line-height: 50px;
  text-align: center;
  margin-top: 15px;
  }
  .text {
    height: 17px;
  margin-top: 13px;

  font-size: 12px;
  font-family: PingFangSC-Regular,PingFang SC;
  font-weight: 400;
  line-height: 17px;
  text-align: center;
  }
  .color2 {
    color: #91a7dc;
  }
}
.box3 {
  height: calc(60vh - 72px);
    min-height: 538px;
  padding: 20px;
  border-radius: 20px;
  margin-left: 14px;
}

.partner-node-collect {
    display: flex;
    -webkit-box-orient: vertical;
    -webkit-box-direction: normal;
    flex-direction: column;
    height: calc(40vh - 48px);
    min-height: 353px;
    background: #fff;
    border-radius: 20px;
    .title h3 {
    margin: 0;
    padding: 0;

  }
  .iconBox {
    text-align: right;
    i {
      font-size: 20px;
      cursor: pointer;
      color: rgb(146, 183, 255);
    }
  }
  .collect {
    width: 154px;
    height: 230px;
    padding-top: 47px;
    padding-left: 38px;
    margin-top: 30px;
    background: linear-gradient(135deg,transparent,#f8f8f9 0) 0 0,linear-gradient(-135deg,transparent 12px,#f8f8f9 0) 100% 0,linear-gradient(-45deg,transparent,#f8f8f9 0) 100% 100%,linear-gradient(45deg,transparent 12px,#f8f8f9 0) 0 100%;
    background-size: 50% 50%;
    background-repeat: no-repeat;
    .count {
      height: 33px;
    font-size: 24px;
    font-family: PingFangSC-Semibold,PingFang SC;
    font-weight: 600;
    color: #072074;
    line-height: 33px;
    }
    .count2 {
      margin-top: 20px;
    }
    .name {
      height: 17px;
    margin-top: 6px;
    font-size: 12px;
    font-family: PingFangSC-Regular,PingFang SC;
    font-weight: 400;
    color: #000412;
    line-height: 17px;
    }
  }
}
.box {
  margin-top: 20px;
  padding: 20px;
}
.abnormal-equipment{
    display: flex;
    -webkit-box-orient: vertical;
    -webkit-box-direction: normal;
    flex-direction: column;
    height: calc(40vh - 48px);
    min-height: 353px;
    background: #fff;
    border-radius: 20px;
    .title h3 {
    margin: 0;
    padding: 0;

  }
  .iconBox {
    text-align: right;
    i {
      font-size: 20px;
      cursor: pointer;
      color: rgb(146, 183, 255);
    }
  }
  .empty {
    padding: 10px;
// height: 100px;
width: 100%;
text-align: center;
-webkit-box-flex: 1;
    flex: 1;
    display: flex;
    -webkit-box-orient: vertical;
    -webkit-box-direction: normal;
    flex-direction: column;
    -webkit-box-pack: center;
    // justify-content: center;
    -webkit-box-align: center;
    // align-items: center;
  }
  .tips {
  text-align: center;
margin-top: 100px;
}
}
.left-shifting {
  margin-left: 20px;
}
</style>
